<?php
session_start();
include("../connections/agriculture.php");
$email=$_POST['email'];
$pass=$_POST['pass'];
$pass2=$_POST['pass2'];
$tel=$_POST['tel'];
if($_SESSION["user"]!=""){
	$user=$_SESSION["user"];
	if($_POST["op"] == "更    新"&&$pass==$pass2) {
	/*include("header.inc.php");
	include("dbconnect.inc.php");
	if($_GET["id"]!="" && $_SESSION["userid"]==1 && is_numeric($_GET["id"])) {
		$id = $_GET["id"];
	}else {
		$id = $_SESSION["userid"];
	}*/
	$sql = "update  users set `user_pass` =  '$pass',
	`user_email` =  '$email',
	`user_tel` =  '$tel' 
	WHERE  `user_name`='$user';";
	$res = mysql_query($sql);
	echo'<script language="javascript">window.location= "admin_index.php";</script>';
	if(!$res) {
		echo mysql_error();
		die("数据库出错，请返回重试。");}
	}
	
?>
<script>
	function check_form() {
		password = document.getElementById("pass").value;
		password2 = document.getElementById("pass2").value;
		mail = document.getElementById("mail").value;
		emsg = "";
		if(password != password2) emsg += "两次输入密码不同. \n";
		var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		if(!pattern.test(mail)) emsg += "邮件格式不正确. \n";
		if(emsg != "" ) {
			emsg = "------------------------------------------\n\n"+emsg;
			emsg = emsg+"\n------------------------------------------";
			alert(emsg);
			return false;
		}else {
			return true;
		}
	}
</script>
 <p>&nbsp;</p>
  <p>&nbsp;</p>
   <p>&nbsp;</p>
    <p>&nbsp;</p>
     <p>&nbsp;</p>
 <table align="center">
  <tr>
   <td align="center"><h2><?php echo $_SESSION["user"]; ?>，请谨慎修改信息！！！</h2>
  <form action="edit.php"  method="post" >   
    <div class="form-item">
      <label for="edit-name">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
      <span><?php echo $user; ?></span>
      </div>
      <div class="form-item">
        <label for="edit-pass">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;改后密码：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <input type="password" maxlength="64" name="pass" id="edit-pass"  size="30" value="" class="form-text required" />
        <div class="description">请再次输入您的密码：
        <input type="password" maxlength="64" name="pass2" id="edit-pass2"  size="30" value="" class="form-text required" />
        </div>
      <div class="form-item">
        <label for="edit-mail">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E-mail地址:&nbsp;&nbsp;&nbsp;&nbsp; </label>
        <input type="text" maxlength="64" name="email" id="edit-mail"  size="30"  class="form-text required" />
        <div class="description"></div>
        </div>
      <div class="form-item">
        <label for="edit-tel">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;电话:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
        <input type="text" maxlength="64" name="tel" id="edit-tel"  size="30"  />
        <div class="description"></div>
        </div>
<input type="submit" name="op" value="更    新"  class="form-submit" onclick="return check_form();"  />
      <br /><br />
    </div></form>
    <?
}
    ?>
   </td>
   </tr>
   </table>